perm filename PL.DOC[HAL,HE] blob sn#121117 filedate 1974-09-22 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	FORMAT OF A PL PROGRAM.
C00008 00003	FORMAT OF THE OBJECT PROGRAM PRODUCED BY PTRANS.
C00012 ENDMK
C⊗;
FORMAT OF A PL PROGRAM.


	In  the  following,  a  "list"  of certain elements means any
sequence of these elements delimited  by  one  or  more  "separators"
(i.e. blank,crlf,tab).


	A pl program is a sequence of  "chapters"  delimited  by  the
symbol "$". Each chapter is made of a "header" and a "body". Possible
headers are:

"EXEC_FILES"
"DELIMITERS"
"RESERVED_WORDS"
"NON_TERMINAL_SYMBOLS"
"TYPES"
"CLASSES"
"PRODUCTIONS".

The  only  restriction  on  the  order  of  appearance  is  that  the
PRODUCTIONS chapter must be the last one, and  that  DELIMITERS  must
appear  before   RESERVED_WORDS if  there  are  any  double-character
delimiters.

EXEC_FILES is a list of SAIL files which contain  the  exec  routines
required by the productions.

DELIMITERS  is  a  list  of delimiters. Double delimiters, along with
symbols that have a special meaning to the PL program (like  $)  must
be  enclosed  in  quotes.  No  comment  of any sort may appear in the
DELIMITERS chapter.

RESERVED_WORDS is a list of words to be recognized as reserved by the
compiler.

NON_TERMINAL_SYMBOLS will be stored as reserved words.

TYPES is a list of types other than the standard ones provided by the
scanner (it does'nt hurt to include some of these again).

CLASSES is a list of class lists. A class list consists of the symbol
@,  followed by a class name which must be an identifier not declared
so far, and a list of class members.  A  class  member  is  any  item
previously  defined:  type,  reserved word, delimiter,  or class name
(without the @).

PRODUCTIONS is a list of productions.

A production is: A "left-hand-side", followed by  →,  followed  by  a
"right-hand-side",  followed  by  a  semicolon, followed by a list of
exec routines, followed by a list of branch instructions.

A left-hand side is either a labeled  left-handside,  or  a  list  of
objects   previously  defined  (reserved  words,  delimiters,  types,
classes (without the @)). Double delimiters and "→" must be  enclosed
in  quotes.  Another  legal left-hand side element is the word ANY. A
left-hand side element can be followed  by  a  positive  index,  e.g.
ANY[1].

A   right-hand   side   is  a  list  of  reserved  words,  delimiters
(";","≡","-", "↑","↓", "$" should be enclosed in quotes), or integers
which  are  understood to refer to an indexed left-hand side element.
Another legal right-hand side  element  is  the  word  SAME  (meaning
"don't change that cell").

An  exec  routine  is the name of a SAIL procedure declared in one of
the "EXEC_FILES", or the word SCAN optionally followed by an integer.
If SCAN is included, it must be the last exec routine.

There need not be any branch instructions, but if there is some, they
must appear in the  following  order:
 ↓<label>  (go  recursively  to<label>)  or  ↑  (pop  stack);
 ≡<label>  (success  address) 
¬<label>   (failure address)

	If one  of  the  two  latter  instructions  is  missing,  the
corresponding  address  will  be  understood  to  refer  to  the next
production.

	A production is optionally  followed  by  a  semicolon.  This
semicolon should be present if there is no branch instruction at all,
otherwise PTRANS will try to make an exec routine out of the l.h.s of
the next production.
FORMAT OF THE OBJECT PROGRAM PRODUCED BY PTRANS.

Three files are created by PTRANS: LAB.SAI,EXEC.SAI,and TABLE.SAI.

EXEC.SAI contains the name of all the exec routines  in  a  big  CASE
statement.

LAB.SAI  contains  the declaration of the array LABELS preloaded with
the addresses of all labels used in the program. These addresses  are
production  numbers refering to the array PRODUCTION; they are packed
3 in a word. All jumps are indirect in  the  production  interpreter.
LABELS  starts  at  1 (null labels have usually a special meaning for
the parser).

TABLE.SAI contains the declaration of the preloaded  array  RESWORDS,
the  "triples"  associated  with  classes,  and the array PRODUCTION.
PRODUCTION starts at 1. Production elements are stored 3  in  a  word
(numbered 0,1,2 from "left" to "right"); negative elements have their
bit 0 on.

	A production is represented by the following elements:

NUMFAIL: The address to skip to in case the production does not match
the  input.  If  NUMFAIL  is  positive,  it corresponds to a label in
LABEL; if it is negative,  then  its  opposite  is  the  actual  jump
address  in  case of failure. This corresponds to the case when there
was no "¬" branch instruction in  the  PL  program.  A  null  NUMFAIL
corresponds  to the end of the program.(PTRANS generates it after the
last production).

LEFTNUM: The number of l.h.s elements, followed by  leftnum  elements
giving the code (token number) of these elements. Types are negative;
1-character delimiters are between 0  and  127;  reserved  words  are
above  127.  Classes  are  like  reserved  words,  but are recognized
because their nos. are between the values LOWERCLASS and UPPERCLASS.

RIGHTNUM:  The  number  of  right-hand  side  elements,  followed  by
rightnum  elements.  A  positive  element  is a delimiter or reserved
word; a null element means  "SAME";  a  negative  element,  e.g.  -i,
points at the i-th element of the l.h.s (numbering starts at 1).

EXECNUM:  The number of exec routines, followed by their execnum nos.
(numbering starts at 1);

NUMSCAN: The number of tokens to be scanned, possibly null;

NUMSUCC: The success label. 0 means "next production".

STACKCODE: At interpretation time, i (i>0) means push actual  success
address on procedure stack, and go to label i; <0 means pop stack and
go to address indicated by top; 0 means don't call any procedure.